using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SettlementMissionComplete : SettlementWindow
{
	[SerializeField]
	private NumericalEffect m_ShotsRemain;

	private int m_Star;

	[SerializeField]
	private NumericalEffect m_HitRate;

	[SerializeField]
	private NumericalEffect m_MaxLink;

	[SerializeField]
	private NumericalEffect m_Score;

	[SerializeField]
	private NumericalEffect m_HighScore;

	[SerializeField]
	private NumericalEffect m_FriendHighScore;

	[SerializeField]
	private Animator m_Animator;

	[SerializeField]
	private RectTransform m_NextButtonGO;

	[SerializeField]
	private RectTransform m_BackButtonGO;

	[SerializeField]
	private List<GameObject> m_stars;

	[SerializeField]
	private GameObject m_retryBtnGO;

	[SerializeField]
	private GameObject m_completeTitle;

	[SerializeField]
	private GameObject m_filedTitle;

	private int starAnimationFinishTimes;

	private bool adHaveBeenShown;

	private bool isTutorialLevel => LevelDataIndex.CurrentLevel.FileName.Equals("1-1") || LevelDataIndex.CurrentLevel.FileName.Equals("2-1");

	public void StarAnimEndOnce()
	{
		starAnimationFinishTimes++;
		if (starAnimationFinishTimes == m_Star && !adHaveBeenShown)
		{
			ShowAd(order: false);
		}
	}

	public void Star1AnimBegin()
	{
		ShowAd(order: true);
		starAnimationFinishTimes = 0;
		adHaveBeenShown = false;
	}

	private void ShowAd(bool order)
	{
		if (!isTutorialLevel)
		{
			string fileName = LevelDataIndex.CurrentLevel.FileName;
			int num = int.Parse(fileName.Split('-')[0]);
			int num2 = int.Parse(fileName.Split('-')[1]);
			AdManagerOld.instance.curAd.ShowSpecialInterstitial(order, QiXunAd.PAGE_MAIN, 0, 0);
			adHaveBeenShown = true;
		}
	}

	protected override void OnEnable()
	{
		base.OnEnable();
		m_Animator.SetInteger("Star", m_Star);
		UnityEngine.Debug.Log("STAR:" + m_Star);
		if (ConstantData.LevelDatas.Next(LevelDataIndex.CurrentLevel) == null)
		{
			m_NextButtonGO.gameObject.SetActive(value: false);
			Vector3 v = m_BackButtonGO.anchoredPosition;
			v.x = 0f;
			m_BackButtonGO.anchoredPosition = v;
		}
	}

	public void SetData(MissionPlayer.PlayerData playerData, bool isWin)
	{
		m_ShotsRemain.value = playerData.ShotsRemain;
		m_HitRate.value = (int)(playerData.HitRate * 100f);
		m_MaxLink.value = playerData.MaxCombo;
		m_Score.value = playerData.Score;
		m_HighScore.value = playerData.HighScore;
		m_Star = playerData.Star;
		m_NextButtonGO.gameObject.SetActive(isWin);
		m_retryBtnGO.SetActive(!isWin);
		m_completeTitle.SetActive(isWin);
		m_filedTitle.SetActive(!isWin);
	}

	public override void OnNext()
	{
		LevelDataIndex.CurrentLevel = ConstantData.LevelDatas.Next(LevelDataIndex.CurrentLevel);
		ConstantData.LoadedChapter = ConstantData.LevelDatas.GetChapter(LevelDataIndex.CurrentLevel.FileName);
		ConstantData.LevelDatas.TracingLevel(LevelDataIndex.CurrentLevel.FileName);
		BaseUIController.Instance.RestartScene();
	}

	public override void OnBack()
	{
		endShowAd();
		BaseUIController.Instance.Back2MainScene();
	}

	public override void OnTryAgain()
	{
		BaseUIController.Instance.RestartScene();
	}

	private void endShowAd()
	{
		if (!isTutorialLevel && !adHaveBeenShown)
		{
			adHaveBeenShown = true;
			AdManagerOld.instance.curAd.ShowSpecialInterstitial(isShowBefore: true, QiXunAd.PAGE_MAIN, 0, 0);
		}
	}

	private IEnumerator Show()
	{
		for (int i = 0; i < m_Star; i++)
		{
			m_stars[i].GetComponent<AnimationTools>().Init();
			m_stars[i].GetComponent<AnimationTools>().Trigger("Show");
			yield return new WaitForSeconds(0.2f);
		}
	}

	public void TriggerAnimationEnd()
	{
		adHaveBeenShown = false;
		StartCoroutine(Show());
	}
}
